package edu.ccut.saturn.studio.dialog.validatedialog;

import org.eclipse.jface.viewers.ICellModifier;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.widgets.TableItem;

import edu.ccut.saturn.studio.logic.model.saturn.SaturnArg;

public class MyCellModifierArg implements ICellModifier {
	
	private TableViewer tableViewer;
	
	public MyCellModifierArg(TableViewer tableViewer){
		this.tableViewer = tableViewer;
	}

	public boolean canModify(Object element, String property) {
		return true;
	}

	public Object getValue(Object element, String property) {
		SaturnArg o = (SaturnArg) element;
		if (property.equals("id")) {
			return o.getId();
		} else if (property.equals("arg")) {
			return o.getArg();
		} 
		throw new RuntimeException("" + property); 
	}

	public void modify(Object element, String property, Object value) {
		TableItem item = (TableItem) element;
		SaturnArg o = (SaturnArg)item.getData();
		if (property.equals("arg")) {
			String newArg = (String) value;
			o.setArg(newArg);			
		} else {
			throw new RuntimeException("" + property); 
		}
		tableViewer.update(o, null);
	}
}
